/*
 * Copyright (c) 2012 Sean Connelly
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
 * associated documentation files (the "Software"), to deal in the Software without restriction,
 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all copies or
 * substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
 * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

var assert = require('../assert.js').init();
var common = require('../../src/js/common.js');

exports.run = function(root_dir, test_dir, test_name) {

		assert.that('isArray works for arrays',
			common.isArray([]));
		assert.that('isArray fails for objects',
			!common.isArray({}));
		assert.that('isObject fails for arrays',
			!common.isObject([]));
		assert.that('isObject works for objects',
			common.isObject({}));

		var a = { key: { another: 1 } };
		var b = common.deepCopy(a);
		a.key.another = 2;
		assert.that('deepCopy copies values',
			a.key.another === 2 && b.key.another === 1);
		assert.that('deepCopy copies objects',
			b.key != a.key);

		assert.that('replaceAll works',
			common.replaceAll('abcabcabc', 'bc', 'BC') == 'aBCaBCaBC');

		assert.that('isWhite works',
			common.isWhite(' ') && common.isWhite('\n') && common.isWhite('\t') &&
			!common.isDigit('') && !common.isWhite('a'));
		assert.that('isDigit works',
			common.isDigit('1') && common.isDigit('2') && common.isDigit('0') &&
			!common.isDigit('') && !common.isDigit('F'));
		assert.that('isHex works',
			common.isHex('0') && common.isHex('a') && common.isHex('F') &&
			!common.isHex('') && !common.isHex('G'));
		assert.that('isOct works',
			common.isOct('0') && common.isOct('4') && common.isOct('7') &&
			!common.isOct('') && !common.isOct('8') && !common.isOct('a'));
		assert.that('isBin works',
			common.isBin('0') && common.isBin('1') &&
			!common.isBin('') && !common.isBin('2') && !common.isBin('b'));

		var o = {};
		o[0] = 1;
		assert.that('objectsMatch works',
			common.objectsMatch({ name: 'One', two: 2 }, { two: 2, name: 'One'}) &&
			!common.objectsMatch(1, 2) &&
			common.objectsMatch([1, 2, 3], [1, 2, 3]) &&
			!common.objectsMatch(o, [1]));

		// MYTODO: isAlpha, isLetter, isIdentStart, isIdentMiddle, isWord, upperFirst

		return assert.result();
	};
